<template>
  <el-upload  id="imageUpload"
              action="string"
              :show-file-list="false"
              list-type="picture"
              :before-upload="beforeAvatarUpload"
              :http-request="submitUpload">
    <img v-if="dialoginfo.thumbNailImage" :src="this.proAPI.RESOURCE_URL+dialoginfo.thumbNailImage" class="avatar">
    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  </el-upload>
</template>
<script>
  export default {
    data() {
      return {
        fileList: [],
        dialogImageUrl: '',
        dialogVisible: false,
        uploadUrl:this.proAPI.RESOURCE_URL+this.proAPI.uploadSingleHeadImage
      };
    },
    methods: {
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isPNG = file.type === 'image/png';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG&&!isPNG) {
          this.$message.error('图片格式只能是 JPG或者PNG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('图片大小不能超过 2MB!');
        }
        return (isJPG||isPNG) && isLt2M;
      },
      submitUpload(item) {
        // console.log(item);
        let formData = new FormData()
        formData.append('file', item.file)
        this.$store.commit("saveLoadingMap", {"target": this.proAPI.URLS.uploadSingleHeadImage,id:this.target});
        this.proAPI.postFile(this.proAPI.URLS.uploadSingleHeadImage, formData).then(res => {
          this.dialoginfo.thumbNailImagePath = res.data.thumbNailImage
          this.dialoginfo.imagePath = res.data.imagePath;
        })
      }
    },
    mounted(){
      // console.log("quweuoqwueoqueoqiw");
    }
  }
</script>
<style media="scoped">

</style>
